/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name:login.c
> Author:xxx
> Mail: 
> Created Time: 2024年12月04日 星期三 11时59分19秒
***************************************************/

#include "cJSON.h"
#include "login.h"

//管理员登陆
int gly_login(int client_socket){
	char username[20] = {0};
	char passwd[20] = {0};
	printf("input gly账号:");
	scanf("%s",username);
	printf("input gly密码:");
	scanf("%s",passwd);
	
	//创建json对象
	cJSON* root = cJSON_CreateObject();
	cJSON* type = cJSON_CreateString("gly_login");
	cJSON* username_0 = cJSON_CreateString(username);
	cJSON* passwd_0 = cJSON_CreateString(passwd);
	
	cJSON_AddItemToObject(root,"type",type);
	cJSON_AddItemToObject(root,"username",username_0);
	cJSON_AddItemToObject(root,"passwd",passwd_0);
	
	char *str = (char *)malloc(1024);
	str = cJSON_Print(root);
	printf("%s\n",str);
	write(client_socket,str,strlen(str));
	read(client_socket,str,sizeof(str));
	printf("%s\n",str);
	if(strcmp(str,"success")){
		free(str);
		return 1;
	}
	free(str);
	return 0;
}

//员工登陆
int staff_login(int client_socket){
	char username[20] = {0};
	char passwd[20] = {0};
	printf("input gly账号:");
	scanf("%s",username);
	printf("input gly密码:");
	scanf("%s",passwd);
	
	//创建json对象
	cJSON* root = cJSON_CreateObject();
	cJSON* type = cJSON_CreateString("staff_login");
	cJSON* username_0 = cJSON_CreateString(username);
	cJSON* passwd_0 = cJSON_CreateString(passwd);
	
	cJSON_AddItemToObject(root,"type",type);
	cJSON_AddItemToObject(root,"username",username_0);
	cJSON_AddItemToObject(root,"passwd",passwd_0);
	
	char *str = (char *)malloc(1024);
	str = cJSON_Print(root);
	printf("%s\n",str);
	write(client_socket,str,strlen(str));
	read(client_socket,str,sizeof(str));
	printf("%s\n",str);
	if(strcmp(str,"success")){
		free(str);
		return 1;
	}
	free(str);
	return 0;
}

//家属登陆
int family_login(int client_socket){
	char username[20] = {0};
	char passwd[20] = {0};
	printf("input gly账号:");
	scanf("%s",username);
	printf("input gly密码:");
	scanf("%s",passwd);
	
	//创建json对象
	cJSON* root = cJSON_CreateObject();
	cJSON* type = cJSON_CreateString("family_login");
	cJSON* username_0 = cJSON_CreateString(username);
	cJSON* passwd_0 = cJSON_CreateString(passwd);
	
	cJSON_AddItemToObject(root,"type",type);
	cJSON_AddItemToObject(root,"username",username_0);
	cJSON_AddItemToObject(root,"passwd",passwd_0);
	
	char *str = (char *)malloc(1024);
	str = cJSON_Print(root);
	printf("%s\n",str);
	write(client_socket,str,strlen(str));
	read(client_socket,str,sizeof(str));
	printf("%s\n",str);
	if(strcmp(str,"success")){
		free(str);
		return 1;
	}
	free(str);
	return 0;
}


//家属注册
int family_register(int client_socket){
	char username[20] = {0};
	char passwd[20] = {0};
	printf("input 用户名:");
	scanf("%s",username);
	printf("input 密码:");
	scanf("%s",passwd);
	
	//创建json对象
	cJSON* root = cJSON_CreateObject();
	cJSON* type = cJSON_CreateString("family_register");
	cJSON* username_0 = cJSON_CreateString(username);
	cJSON* passwd_0 = cJSON_CreateString(passwd);
	
	cJSON_AddItemToObject(root,"type",type);
	cJSON_AddItemToObject(root,"username",username_0);
	cJSON_AddItemToObject(root,"passwd",passwd_0);
	
	char *str = (char *)malloc(1024);
	str = cJSON_Print(root);
	printf("%s\n",str);
	write(client_socket,str,strlen(str));
	read(client_socket,str,sizeof(str));
	printf("%s\n",str);
	if(strcmp(str,"success")){
		free(str);
		return 1;
	}
	free(str);
	return 0;
}





















